import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:t2app/src/Config.dart';
import 'package:t2app/src/common/PhoteViewSimpleScreen.dart';
import 'package:t2app/src/util/log_util.dart';

class NoServer_Scroll_Swiper_View extends StatefulWidget{

  @override
  State<StatefulWidget> createState() {
    return  new IndexViewState();
  }
}

class IndexViewState extends State<NoServer_Scroll_Swiper_View>{
  List _leimuImages = ["assets/images/leimu/1.jpg",
        "assets/images/leimu/2.jpg"
  ];
  List _girlImages = ["assets/images/girl/1.jpg",
    "assets/images/girl/2.jpg"
  ];
  List _jiaoxiaoImages = ["assets/images/jiaoxiao/1.png",
  "assets/images/jiaoxiao/2.png"
  ];

  Widget _swiperBuilder(BuildContext context, int index) {
    return (Image.asset(
      _leimuImages[index],
      fit: BoxFit.cover,
    ));
  }

  Widget _swiperBuilder2(BuildContext context, int index) {
    return (Image.asset(
      _girlImages[index],
      fit: BoxFit.cover,
    ));
  }
  Widget _swiperBuilder3(BuildContext context, int index) {
    return (Image.asset(
      _jiaoxiaoImages[index],
      fit: BoxFit.cover,
    ));
  }

  Swiper _swiper(bulider, images){
    return Swiper(
      itemBuilder: bulider,
      itemCount: images.length,
      control: new SwiperControl(),
      scrollDirection: Axis.horizontal,
      autoplay: true,
      onTap: (index){
          Navigator.of(context).push(MaterialPageRoute(builder:(context){
            return PhotoViewSimpleScreen(
              imageProvider: AssetImage(images[index]),
              heroTag: images[index],
            );
        }));
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: Config.APP_BAR(title: new Text("滚动轮播效果")),
        body: SingleChildScrollView(child: new Container(
          color: Config.THEME.primaryColorLight,
          width: MediaQuery.of(context).size.width,
          child: new Column(
            children: [
              new Container(
                    width: MediaQuery.of(context).size.width,
                    height:MediaQuery.of(context).size.height,
                    child: _swiper(_swiperBuilder,_leimuImages)
               ),
              new Container(
                  margin: EdgeInsets.only(top: 1),
                  width: MediaQuery.of(context).size.width,
                  height:MediaQuery.of(context).size.height,
                  child: _swiper(_swiperBuilder2,_girlImages)
              ),
              new Container(
                  margin: EdgeInsets.only(top: 1),
                  width: MediaQuery.of(context).size.width,
                  height:MediaQuery.of(context).size.height,
                  child: _swiper(_swiperBuilder3,_jiaoxiaoImages)
              ),
            ],
          ),
        )
       )
    );
  }

}
